<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px">
      <el-form-item label="交接人">
        <el-select placeholder="请选择交接人" filterable v-model="fromUser" @change="takeFromUser">
          <el-option v-for="dict in users"
                     :key="dict.userId"
                     :label="dict.nickName"
                     :value="dict.userId"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="">
        <el-button :disabled="!fromUser" type="success" @click="handleQuery">查询交接业务</el-button>
      </el-form-item>
      <el-form-item label="接收人">
        <el-select placeholder="请选择接收人" filterable v-model="toUser" @change="takeToUser">
          <el-option v-for="dict in toUserList"
                     :key="dict.userId"
                     :label="dict.nickName"
                     :value="dict.userId"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-radio-group class="drawer-radio" v-model="picked">
        <el-radio :label="1" @click.native.prevent="handleChangeitem(1)" style="margin-top: 10px">复制</el-radio>
      </el-radio-group>

      <el-form-item label="">
        <el-button :disabled="!toUser || !fromUser " type="primary" @click="submitForm" style="margin-left: 15px">交接</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="salespermissionList">
      <el-table-column label="用户" align="center" prop="realName" >
        <template slot-scope="scope">
          <span>{{scope.row.realName + '-' + scope.row.telphone}}</span>
        </template>
      </el-table-column>
      <el-table-column label="权限" align="center" prop="permissiontext" width="100" />
      <el-table-column label="组织" align="center" prop="orgName" />
      <el-table-column label="部门" align="center" prop="depName" />
      <el-table-column label="库房" align="center" prop="storeName" />
      <el-table-column label="状态" align="center" prop="status" width="60">
        <template slot-scope="scope">
          <span v-if="scope.row.status == 1">正常</span>
          <span v-if="scope.row.status == 2">失效</span>
        </template>
      </el-table-column>
      <el-table-column label="创建时间" align="center" prop="createtime" width="80">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createtime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
    </el-table>

<!--    <pagination-->
<!--      v-show="total>0"-->

<!--      @pagination="getList"-->
<!--    />-->

  </div>
</template>

<script>
import {transListSalespermission, trans, usertransfer} from "@/api/permission/salespermission";
import {getUserList} from "@/api/public";
import {getTranstoUserList} from "@/api/system/user";

export default {
  name: "permissiontrans",
  data() {
    return {
      // 遮罩层(转圈)
      loading: false,
      loading2: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 权限管理表格数据
      salespermissionList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 类型字典
      typeOptions: [],
      // 查询参数
      queryParams: {
        // pageNum: 1,
        // pageSize: 10,
        userId: null,
        status: null,
        srguid: null,
        deptId: null
      },
      // 表单参数
      form: {
        userId: '',
        deptId: ''
      },
      permissionDef: [],
      departOption: [],
      storeroomOption: [],
      storeroomOption2: [],
      userOption: [],
      departShow: false,
      srShow:false,
      permissionShow: false,
      permissionOptions: [],
      permissions : [],
      deptOptions: [],
      orgs: [],
      permisOptions: [],
      fromUser: '',
      toUser: '',
      picked:"",
      users:[],
      toUserList:[]
    };
  },
  created() {
    // this.getList();
    this.getUserList();
  },
  methods: {
    //复制按钮操作
    handleChangeitem(e){
      e===this.picked?this.picked=0:this.picked=e;
      console.log(this.picked);
    },

    takeFromUser(uid) {
      this.getToUsers(uid);
      this.toUser = '';
      this.getList();
    },
    takeToUser(uid){
      this.subStauts=true;
    },
    /** 查询交接人*/
    getUserList() {
      getUserList().then(response => {
          this.users = response.data;
        }
      );
    },

    /** 查询接交人 */
    getToUsers(id) {
      this.toUserList = [];
      getTranstoUserList({Id: id}).then(response => {
        this.toUserList = response.data;
      });
    },

    /** 查询权限管理列表 */
    getList() {
      this.picked=0;
      this.loading = true;
      this.queryParams.userId=this.fromUser;
      transListSalespermission(this.queryParams).then(response => {
        this.salespermissionList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },

    /** 查询按钮操作 */
    handleQuery() {
      // this.queryParams.pageNum = 1;
      this.getList();
    },

    /** 提交按钮 */
    submitForm() {
      this.subStauts = true;
      this.$confirm('确定要执行该操作?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',

      }).then(async () => {
        await trans({fromUserId: this.fromUser, toUserId: this.toUser,picked:this.picked});
        this.msgSuccess("交接成功");
        this.getList();
        this.subStauts = false;
      });
    },
  }
};
</script>
